package com.stox.core.ui.swing.widget;

import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.IOException;
import java.util.List;


public class ListTransferable implements Transferable {

	public static final DataFlavor listFlavor = new DataFlavor(List.class,"List");
	private List<?> list;
	
	public ListTransferable(List<?> list) {
		this.list = list;
	}
	
	@Override
	public DataFlavor[] getTransferDataFlavors() {
		return new DataFlavor[]{listFlavor};
	}

	@Override
	public boolean isDataFlavorSupported(DataFlavor flavor) {
		return flavor.equals(listFlavor);
	}

	@Override
	public Object getTransferData(DataFlavor flavor)
			throws UnsupportedFlavorException, IOException {
		if(flavor.equals(listFlavor)){
			return list;
		}
		throw new UnsupportedFlavorException(flavor);
	}

}
